<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>

<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con">
            <span>新建证件编制</span><div class="move_title"></div><?php include "../public/sub.php";?></div>
    </div>
    <div class="main-container">
        <div class="block-generic">


            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>基本信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>证书分类</label>
                        <div class="layui-input-block">
                            <select class="layui-select" key="1" name="cert_type" id="cert_type" lay-filter="cert_type"></select>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>证书名称</label>
                        <div class="layui-input-block">
                            <input type="text" id="cert_name" name="cert_name" autocomplete="off" placeholder="名称须与证书库中的证书名称保持一致" clearable class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">证书专业</label>
                        <div class="layui-input-block">
                            <input type="text" id="cert_major" name="cert_major" autocomplete="off" placeholder="专业须与证书库中的专业名称保持一致" clearable class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>需求数量</label>
                        <div class="layui-input-block">
                            <input type="number" id="num" name="num" autocomplete="off" clearable class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label" id="explain_label">备注</label>
                        <div class="layui-input-block">
                            <textarea id="explain" name="explain" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>
<script>
    $("#commentForm").validate({
        rules: {
            num: {required: true},
            cert_name: {required: true},
        },
        messages:{
            num: {required: "请输入需求数量"},
            cert_name: {required: "请填写证书名称"},
        }
    });

    layui.use(['laytp', 'form'], function() {
        var form = layui.form;
        render_input_attr();

        facade.ajax({url: ask_cert_form_add, type:'get', data:{}}).done(function(res){
            if (res.code === 2000) {
                cert_typeArr = res.data.cert_type;
                var str = '<option value="">请选择证书分类</option>';
                for(var i=0; i<cert_typeArr.length; i++){
                    str += '<option value="'+cert_typeArr[i].value+'">'+cert_typeArr[i].name+'</option>';
                }
                $('#cert_type').html(str);
                render_from();
            }
        });

        form.on('submit(add)', function(data){
            var validRes = $("#commentForm").valid();
            if(!data.field.cert_type){
                formValid('cert_type', '请选择证书分类'); validRes = false;
            }else{
                formValid('cert_type', '');
            }
            if(!validRes){return false;}

            facade.ajax({url: ask_cert_form_add, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    dataPostTimeOut();
                }
            });
            return false;
        });
    });
</script>
</body>
</html>
